package com.bwie.controller;

import com.bwie.pojo.TbActivity;
import com.bwie.pojo.TbGoodsVo;
import com.bwie.pojo.TbUser;
import com.bwie.service.TbGoodsService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/goods/goods")
public class TbGoodsController {
    @Autowired
    TbGoodsService tbGoodsService;

    /***
     *@Description:商品信息列表
     * @param pageInfoVo
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/4 10:22
     *
     */
    @PostMapping("/TbGoodsList")
    public R TbGoodsList(@RequestBody PageInfoVo pageInfoVo) {
        return tbGoodsService.TbGoodsList(pageInfoVo);
    }
    /***
     *@Description:根据id查询下拉框
     * @param id
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/4 11:18
     *
     */
    @PostMapping("/TbSortList/{id}")
    public R TbSortList(@PathVariable(name = "id") Integer id) {
        return tbGoodsService.TbSortList(id);
    }
    /***
     *@Description:文件上传
     * @param file
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/4 11:47
     *
     */
    @PostMapping("/OssUpload")
    public R OssUpload(@RequestBody MultipartFile file) throws IOException {
        return tbGoodsService.OssUpload(file);
    }
    /***
     *@Description:保存商品信息
     * @param tbGoodsVo
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/4 17:15
     *
     */
    @PostMapping("/saveTbGoods")
    public R saveGoods(@RequestBody TbGoodsVo tbGoodsVo) {
        return tbGoodsService.saveGoods(tbGoodsVo);
    }
    /***
     *@Description:推荐
     * @param id
     * @param right
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/5 20:51
     *
     */
    @PostMapping("/recommend/{id}/{right}")
    public R recommend(@PathVariable(name = "id") Integer id,@PathVariable(name = "right") Integer right) throws TemplateException, IOException {
        return tbGoodsService.recommend(id,right);
    }
    /***
     *@Description:活动列表
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/5 20:52
     *
     */
    @PostMapping("/TbActivityList")
    public R TbActivityList() {
        return tbGoodsService.TbActivityList();
    }
    /***
     *@Description:保存活动信息
     * @param tbActivity
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/5 20:54
     *
     */
    @PostMapping("/saveTbActivity")
    public R saveTbActivity(@RequestBody TbActivity tbActivity) {
        return tbGoodsService.saveTbActivity(tbActivity);
    }
    /***
     *@Description:用户登录
     * @param tbUser
     * @return com.bwie.utils.R
     * @author 26440
     *@date 2024/7/5 21:00
     *
     */
    @PostMapping("/userLogin")
    public R userLogin(@RequestBody TbUser tbUser) {
        return tbGoodsService.userLogin(tbUser);
    }
    @PostMapping("/getByIdGoods/{id}")
    public R getByIdGoods(@PathVariable(name = "id") Integer id) throws TemplateException, IOException {
        return tbGoodsService.getByIdGoods(id);
    }
}
